package info.androidhive.tabsswipe;



import java.util.List;

import com.example.newscrolling.enity.Movie_d;
import com.example.newscrolling.service.UserDtDAO;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailActivity extends Activity {
	
	
	private TextView tV1;
	private TextView tV2;
	private TextView tV3;
	private TextView tV4;
	private TextView tV5;
	private TextView tV6;
	private TextView tV7;
	private ImageView iV1;
	
	
	private UserDtDAO dtDao;
	private List<Movie_d> d_list;
	private Movie_d movie_d;
	
	private static final String TAG = "DetailActivity";
	
	
	private String name;
	private String type;
	private String date;
	private String time;
	private String direct;
	private String actor;
	private String summary;
	private Bitmap bit;
	
	
	private int position;
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail);
		initView();
		initHandler();
		
	}

	

	private void initHandler() {
		// TODO Auto-generated method stub
		
	}



	private void initView() {
		// TODO Auto-generated method stub
		
		tV1 = (TextView)findViewById(R.id.tV1);
		tV2 = (TextView)findViewById(R.id.tV2);
		tV3 = (TextView)findViewById(R.id.tV3);
		tV4 = (TextView)findViewById(R.id.tV4);
		tV5 = (TextView)findViewById(R.id.tV5);
		tV6 = (TextView)findViewById(R.id.tV6);
		tV7 = (TextView)findViewById(R.id.tV7);
		iV1 = (ImageView)findViewById(R.id.iV1);
		
		dtDao = new UserDtDAO(this);
		Movie_d movie_d = new Movie_d();
		getData();
	}



	private void getData() {
		// TODO Auto-generated method stub
		
		
		Bundle bundle = this.getIntent().getExtras();
		Log.i(TAG,"1");
		position = bundle.getInt("M_POSITION");
		Log.i(TAG,"2");
		movie_d = dtDao.getUserById1(position);
		Log.i(TAG,"3");
		name = "片名  :" + movie_d.getName();
		Log.i(TAG,"4");
		tV1.setText(name);
		Log.i(TAG,"5");
		date = "上映日期 :" + movie_d.getDate();
		tV2.setText(date);
		type = "類型 :" + movie_d.getType();
		tV3.setText(type);
		time = "片長  :" + movie_d.getTime();
		tV4.setText(time);
		direct = "導演 :" + movie_d.getDirect();
		tV5.setText(direct);
		actor = "演員 :" + movie_d.getActor();
		tV6.setText(actor);
		summary = "概要 :" + movie_d.getSummary();
		tV7.setText(summary);
		
		
		
//		
		// 取得資料庫對應電影的名稱
//		name = dtDao.getName(position);
//		Log.i(TAG,"3");
//		tV1.setText(name);
//		Log.i(TAG,"4");
//
//		// 取得資料庫對應電影的時間
//		date = dtDao.getDate(position);
//		Log.i(TAG,"5");
//		tV2.setText(date);
//		Log.i(TAG,"6");
//
//		// 取得資料庫對應電影的類型
//		type = dtDao.getType(position);
//		Log.i(TAG,"7");
//		tV3.setText(type);
//		Log.i(TAG,"8");
//
//		// 取得資料庫對應電影的片長
//		try {
//			time = dtDao.getTime(position);
//			tV4.setText(time);
//		} catch (Exception ex) {
//			ex.toString();
//		}
//
//		// 取得資料庫對應電影的導演
//		try {
//			direct = dtDao.getDirect(position);
//			tV5.setText(direct);
//		} catch (Exception ex) {
//			ex.toString();
//		}
//
//		// 取得資料庫對應電影的演員
//		try {
//			actor = dtDao.getActor(position);
//			tV6.setText(actor);
//		} catch (Exception ex) {
//			ex.toString();
//		}
//		
//		// 取得資料庫對應電影的概要
//		
//		try {
//			summary = dtDao.getSummary(position);
//			tV7.setText(summary);
//		} catch (Exception ex) {
//			ex.toString();
//		}
//
//		// 取得資料庫對應電影的照片
		try {
			bit = dtDao.getBmp(position);
			iV1.setImageBitmap(bit);
		} catch (Exception ex) {
			ex.toString();
		}
		
		
		
	}


}
